﻿using UnityEngine;
using System.Collections;
namespace net{
	public class NetFire : MonoBehaviour {
		NetCtrl ctrl;
		private NetCtrl Player;
		private float bulletOffset = 0.75f;
		public Vector3 pos;
		
		
		void Start(){
			if (Application.platform != RuntimePlatform.Android) {
				return;
			}

			ctrl = GetComponent<NetCtrl> ();
			pos = transform.position;
			Player = transform.GetComponent<NetCtrl>();

		}
		
		// Update is called once per frame
		void Update () {
			
		}
		void Test(){
			Debug.Log("Gun Test");
			
		}
		void shot(){	
			Debug.Log("shot!");
			pos = transform.position;
			Vector3 bulletPos = Vector3.zero;
			int direction = Common.UP ;
			
			// 死了就不能打了,打过了也不能打
			if (!ctrl.state.isAlive||!ctrl.state.readyToFire) {
				return;
			}
			
			if (Player.state.direction == Common.UP) {
				direction = Common.UP;
				bulletPos = new Vector3(pos.x, pos.y + bulletOffset, pos.z);
			}
			else if (Player.state.direction == Common.DOWN) {
				direction = Common.DOWN;
				bulletPos = new Vector3(pos.x, pos.y - bulletOffset, pos.z);
			}
			else if( Player.state.direction == Common.LEFT) {
				direction = Common.LEFT;
				bulletPos = new Vector3(pos.x - bulletOffset, pos.y, pos.z);
			}
			else if (Player.state.direction == Common.RIGHT) {
				direction = Common.RIGHT;
				bulletPos = new Vector3(pos.x + bulletOffset, pos.y, pos.z);
			}
			
			 
			GetComponent<NetBullet>().NewBomb(direction, bulletPos,gameObject,true);
			ctrl.state.readyToFire = false;
			// biu
			AudioSource audioSource = GetComponent<AudioSource> ();
			audioSource.clip = Resources.Load ("mp3/biu") as AudioClip;
			audioSource.Play ();
		}
	}
}